import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home",
  },
  // 首页
  {
    path: "/home",
    name: "home",

    component: () => import("../views/home/index.vue"),
  },
  // 定位
  {
    path: "/home/main",
    name: "main",
    meta: {
      title: "定位",
    },
    component: () => import("../views/home/main/index.vue"),
  },
  // 搜索
  {
    path: "/home/search",
    name: "search",
    meta: {
      title: "商品搜索",
    },
    component: () => import("../views/home/search/index.vue"),
  },
  // 制造商列表页
  {
    path: "/home/brand",
    name: "brand",
    meta: {
      title: "制造商",
    },
    component: () => import("../views/home/brand/index.vue"),
  },
  // 制造商详情
  {
    path: "/home/brand/branddetail",
    name: "branddetail",
    meta: {
      title: "制造商详情",
    },
    component: () => import("../views/home/brand/branddetail/index.vue"),
  },
  // 更多商品
  {
    path: "/home/goods",
    name: "home_goods",
    meta: {
      title: "更多商品",
    },
    component: () => import("../views/home/goods/index.vue"),
  },
  // 专题
  {
    path: "/topic",
    name: "topic",
    component: () => import("../views/topic/index.vue"),
  },

  // 专题详情
  {
    path: "/topic/topicdetail",
    name: "topicdetail",
    meta: {
      title: "专题详情",
    },
    component: () => import("../views/topic/topicdetail/index.vue"),
  },
  // 分类
  {
    path: "/category",
    name: "category",
    component: () => import("../views/category/index.vue"),
  },
  // 分类商品
  {
    path: "/category/goods",
    name: "category_goods",
    meta: {
      title: "分类商品",
    },
    component: () => import("../views/category/goods/index.vue"),
  },
  // 购物车
  {
    path: "/cart",
    name: "cart",
    component: () => import("../views/cart/index.vue"),
  },
  // 购物车订单确认
  {
    path: "/cart/orderconfirm",
    name: "orderconfirm",
    meta: {
      title: "支付",
    },
    component: () => import("../views/cart/orderconfirm/index.vue"),
  },
  // 我的
  {
    path: "/my",
    name: "my",
    component: () => import("../views/my/index.vue"),
  },
  {
    path: "/my/feedback",
    name: "feedback",
    meta: {
      title: "反馈",
    },
    component: () => import("../views/my/feedback/index.vue"),
  },
  {
    path: "/my/collect",
    name: "collect",
    meta: {
      title: "我的收藏",
    },
    component: () => import("../views/my/collect/index.vue"),
  },
  // 商品详情页
  {
    path: "/goodsdetail",
    name: "goods_detail",
    component: () => import("../views/goodsdetail/index.vue"),
  },
  // 地址管理
  {
    path: "/addressmanage",
    name: "addressmanage",
    meta: {
      title: "我的地址",
    },
    component: () => import("../views/addressmanage/index.vue"),
  },
  // 新增地址&编辑地址
  {
    path: "/addressmanage/editaddress",
    name: "editaddress",
    meta: {
      title: "新建地址",
    },
    component: () => import("../views/addressmanage/editaddress/index.vue"),
    beforeEnter(to, from, next) {
      to.meta.title = to.query.id ? "地址编辑" : "新建地址";
      next();
    },
  },
];

const router = new VueRouter({
  routes,
});

export default router;
